﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using OracleDAL;

namespace BLL.Topo
{
    /// <summary>
    /// 业务逻辑类SUBSYS_LOGIN 的摘要说明。
    /// </summary>
    public class InformationUtilization
    {
        private readonly OracleDAL.Common.mysqldata ora = new OracleDAL.Common.mysqldata();
        /// <summary>
        /// 
        /// </summary>
        public InformationUtilization() { }
        /// <summary>
        /// 获取大运会重点监控方案列表
        /// </summary>
        /// <returns></returns>
        /*public DataSet GetProgramList()
        {
            return ora.GetProgramList();
        }*/
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string PRODUCENAME, string[,] PARAM, string[] VALUES)
        {
            return ora.GetList(PRODUCENAME, PARAM, VALUES);
        }
        /// <summary>
        /// 获取重点监视基站列表
        /// </summary>
        /// <param name="USERISN">用户ID</param>
        /// <returns></returns>
        public string GetTBSID(string USERISN)
        {
            string TBDIDstr = string.Empty;
            DataSet ds = ora.GetTBSID(USERISN);
            if (ds != null&&ds.Tables.Count>0 && ds.Tables[0].Rows.Count > 0)
            {
                int length = ds.Tables[0].Rows.Count;
                for (int i = 0; i < length; i++)
                {
                    TBDIDstr += ds.Tables[0].Rows[i]["NE_ID"];
                    if (i < length - 1)
                    {
                        TBDIDstr += ",";
                    }
                }
                TBDIDstr = "'" + TBDIDstr.Replace(",", "','") + "'";
            }
            return TBDIDstr;
        }
        /// <summary>
        /// 获取基站信道占用百分比
        /// </summary>
        /// <param name="PRODUCENAME">存储过程名称</param>
        /// <param name="PARAM">参数名称及类型</param>
        /// <param name="VALUES">参数值</param>
        /// <param name="TYPE">类型</param>
        /// <returns></returns>
        public List<Model.Topo.InformationUtilization> GetModelList(string PRODUCENAME, string[,] PARAM, string[] VALUES, string TYPE)
        {
            DataSet ds = GetList(PRODUCENAME, PARAM, VALUES);
            List<Model.Topo.InformationUtilization> modelList = new List<Model.Topo.InformationUtilization>();
            Model.Topo.InformationUtilization model;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                int length = ds.Tables[0].Rows.Count;
                switch (TYPE.ToUpper())
                {
                    case "ALL":
                        string strArea = string.Empty;
                        string strAreaTmp = string.Empty;
                        for (int i = 0; i < length; i++)
                        {
                            model = new Model.Topo.InformationUtilization();
                            strAreaTmp = ds.Tables[0].Rows[i]["RXLEV"].ToString().Length == 0 ? "深圳" : ds.Tables[0].Rows[i]["RXLEV"].ToString();
                            if (strArea != strAreaTmp)
                            {
                                strArea = strAreaTmp;
                                model.NODEID = (Convert.ToInt32("10000") + modelList.Count + 1).ToString();
                                model.NODENAME = strArea;
                                model.TYPE = "UNIT";
                                model.UTILIZATION = string.Empty;
                                modelList.Add(model);
                                model = new Model.Topo.InformationUtilization();
                            }
                            model.NODEID = ds.Tables[0].Rows[i]["NE_ID"].ToString();
                            model.LAID = ds.Tables[0].Rows[i]["LAID"].ToString();
                            model.NODENAME = ds.Tables[0].Rows[i]["CHINA_NAME"].ToString();
                            model.TYPE = "LEAF";
                            model.UTILIZATION = ds.Tables[0].Rows[i]["RESERVQUOTIETY"].ToString();
                            model.TIMESTAMP = ds.Tables[0].Rows[i]["TIMESTAMP"].ToString();
                            modelList.Add(model);
                        }
                        break;
                    case "LEAF":
                        for (int i = 0; i < length; i++)
                        {
                            model = new Model.Topo.InformationUtilization();
                            model.NODEID = ds.Tables[0].Rows[i]["NE_ID"].ToString();
                            model.LAID = ds.Tables[0].Rows[i]["LAID"].ToString();
                            model.NODENAME = ds.Tables[0].Rows[i]["CHINA_NAME"].ToString();
                            model.TYPE = "LEAF";
                            model.UTILIZATION = ds.Tables[0].Rows[i]["RESERVQUOTIETY"].ToString();
                            model.TIMESTAMP = ds.Tables[0].Rows[i]["TIMESTAMP"].ToString();
                            modelList.Add(model);
                        }
                        break;
                    case "UNIT":
                        string strArea1 = string.Empty;
                        string strAreaTmp1 = string.Empty;
                        for (int i = 0; i < length; i++)
                        {
                            model = new Model.Topo.InformationUtilization();
                            strAreaTmp1 = ds.Tables[0].Rows[i]["RXLEV"].ToString().Length == 0 ? "深圳" : ds.Tables[0].Rows[i]["RXLEV"].ToString();
                            if (strArea1 != strAreaTmp1)
                            {
                                strArea1 = strAreaTmp1;
                                model.NODEID = (Convert.ToInt32("10000") + modelList.Count + 1).ToString();
                                model.NODENAME = strArea1;
                                model.TYPE = "UNIT";
                                model.LAID = ds.Tables[0].Rows[i]["LAID"].ToString();
                                model.UTILIZATION = string.Empty;
                                modelList.Add(model);
                                model = new Model.Topo.InformationUtilization();
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            return modelList;
        }
        /// <summary>
        /// 获取视频信息
        /// </summary>
        /// <param name="USERISN">用户ISN</param>
        /// <returns></returns>
      /*  public string GetVideo(string USERISN)
        {
            string strVideo = string.Empty;
            DataSet ds = new OracleDAL.Topo.InformationUtilization().GetVideo(USERISN);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                int length = ds.Tables[0].Rows.Count;
                for (int i = 0; i < length; i++)
                {
                    strVideo += ds.Tables[0].Rows[i]["IP"] + ":" + ds.Tables[0].Rows[i]["CHANNEL"].ToString() + " ";
                }
            }
            return strVideo;
        }*/
        /// <summary>
        /// 获取重点监控方案信息
        /// </summary>
        /// <param name="PROGRAMID">方案ID</param>
        /// <returns></returns>
        /*public DataSet GetProgram(string PROGRAMID)
        {
            return new OracleDAL.Topo.InformationUtilization().GetProgram(PROGRAMID);
        }*/
        /// <summary>
        /// 获取重点监控方案下选基站ID列表
        /// </summary>
        /// <param name="PROGRAMID">方案ID</param>
        /// <returns></returns>
       /* public DataSet GetProgramTBSList(string PROGRAMID)
        {
            return new OracleDAL.Topo.InformationUtilization().GetProgramTBSList(PROGRAMID);
        }*/
        /// <summary>
        /// 更新方案可用，唯一性
        /// </summary>
        /// <param name="PROGRAMID">方案ID</param>
        /// <returns></returns>
        /*public int SetProgramUsed(string PROGRAMID)
        {
            return new OracleDAL.Topo.InformationUtilization().SetProgramUsed(PROGRAMID);
        }*/
        /// <summary>
        /// 删除方案
        /// </summary>
        /// <param name="PROGRAMID">方案ID</param>
        /// <returns></returns>
       /* public int DeleteProgramUsed(string PROGRAMID)
        {
            return new OracleDAL.Topo.InformationUtilization().DeleteProgramUsed(PROGRAMID);
        }*/
        /// <summary>
        /// 更新方案下的基站ID列表
        /// </summary>
        /// <param name="strSQL">需要执行的sql语句</param>
        /// <returns></returns>
        /*public int UpdateProgramTBSList(string strSQL)
        {
            return new OracleDAL.Topo.InformationUtilization().UpdateProgramTBSList(strSQL);
        }*/
        /// <summary>
        /// 获取方案列表
        /// </summary>
        /// <param name="PROGRAMID"></param>
        /// <param name="PROGRAMTYPE"></param>
        /// <returns></returns>
        public DataSet GetProgramList(string PROGRAMID, string PROGRAMTYPE)
        {
            return new OracleDAL.Topo.InformationUtilization().GetProgramList(PROGRAMID, PROGRAMTYPE);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SQL"></param>
        /// <returns></returns>
        public int ExcelSQL(string SQL)
        {
            return new OracleDAL.Topo.InformationUtilization().ExcelSQL(SQL);
        }
    }
}
